package controller

import (
	"gin/response"
	"gin/service"
	"gin/types"
	"github.com/gin-gonic/gin"
)

type ProjectTaskProgress struct {
}

// GetTaskDeliveryCount 查询任务交付率
func (p *ProjectTaskProgress) GetTaskDeliveryCount(ctx *gin.Context) {

	var QueryParam types.GetProjectTaskProcessTotalReq
	err := ctx.ShouldBindJSON(&QueryParam)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var ProjectService service.ProjectTaskProgress
	resData, queryErr := ProjectService.GetTaskDeliveryCount(ctx, QueryParam)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

// GetTaskDoneCount 查询任务完成情况
func (p *ProjectTaskProgress) GetTaskDoneCount(ctx *gin.Context) {

	var QueryParam types.GetProjectTaskProcessTotalReq
	err := ctx.ShouldBindJSON(&QueryParam)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var ProjectService service.ProjectTaskProgress
	resData, queryErr := ProjectService.GetTaskDoneCount(ctx, QueryParam)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

func (p *ProjectTaskProgress) GetWorkLoadCount(ctx *gin.Context) {

	var QueryParam types.GetProjectTaskProcessTotalReq
	err := ctx.ShouldBindJSON(&QueryParam)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}

	var ProjectService service.ProjectTaskProgress
	resData, queryErr := ProjectService.GetWorkLoadCount(ctx, QueryParam)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}

func (p *ProjectTaskProgress) GetStepCategoryProgress(ctx *gin.Context) {

	var QueryParam types.GetTaskDeliveryCountReq
	err := ctx.ShouldBindJSON(&QueryParam)

	if err != nil {
		response.Fail(ctx, nil, err.Error())
		return
	}
	//userInfo := service.GetUserInfoFromContext(ctx, "userInfo")

	var ProjectService service.ProjectTaskProgress
	//resData, queryErr := ProjectService.GetStepCategoryProgress(ctx, QueryParam, userInfo)
	resData, queryErr := ProjectService.GetStepCategoryProgressRow(ctx, QueryParam)
	if queryErr != nil {
		// 查询失败
		response.Fail(ctx, nil, queryErr.Error())
	} else {
		// 查询成功
		response.Success(ctx, gin.H{"data": resData}, "success")
	}
}
